LCD INTERFACING WITH AVR
In this project, we will learn How to interface a 16X2 alphanumeric LCD with AVR ATmega16 microcontroller using 8-bit interfacing method.
Synopsis

LCDs (Liquid Crystal Displays) are used for displaying status or parameters in embedded systems. LCD 16x2 is a 16 pin devices which has 8 data pins (D0-D7) and 3 control pins (RS, RW, EN). The remaining 5 pins are for supply and backlight for the LCD.

The control pins help us configure the LCD in command mode or data mode. They also help configure read mode or write mode and also when to read or write.

LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on requirement of application. In order to use it we need to send certain commands to the LCD in command mode and once the LCD is configured according to our need, we can send the required data in data mode.

In this project, we will learn How to interface a 16X2 alphanumeric LCD with AVR ATmega16 microcontroller using 8-bit interfacing method.

Description

LCD (Liquid Crystal Display) screen is an electronic display module. There are two methods to interface any alphanumeric LCD with AVR ATmega16 microcontroller: 8-bit and 4-bit interfacing method. In 8-bit interfacing method, all the eight data pins of the alphanumeric LCD are used and in 4-bit interfacing method, only the upper 4 data pins (D4, D5, D6 and D7) of the alphanumeric LCD are used to send 8-bit data (or command) to the alphanumeric LCD from the microcontroller. In 8-bit method, the 8-bit data (or command) is sent at a time using the 8 data lines of the alphanumeric LCD but in 4-bit method, the 8-bit data (or command) cannot be sent at a time to the alphanumeric LCD. So, the upper 4 bits of data (or command) are sent first and the lower 4 bits are sent later.

ATmega16 is a Low-power AVR 8-bit Microcontroller. The crystal oscillator will provide the clock to the microcontroller. The capacitors connected to the crystal will act as filters and help the crystal to resonate and oscillates to its parallel resonate mode.

The potentiometer which is connected to the pin 3 and pin2 of LCD will help to adjust the contrast of the LCD.

Different commands and there hexadecimal code generally used by the programmer while displaying the data.


Proteus design for LCD interfacing with AVR


Orcad design for LCD interfacing with AVR


LCD Interfacing with AVR

/*  Name     : Main.c
 *  Purpose  : Source code for LCD Interfacing with ATMEGA16.
 *  Author   : GEMICATES
 *  Date     : 10-07-2017
 *  Website  : www.gemicates.org
 *  Revision : None
 */

#include<avr/io.h>				// Header File for ATMEGA16
#include<util/delay.h>			        // Include Delay Function

#define LCD PORTD				// To Set Port D as LCD'S DATA I/P Purpose
#define CNT PORTA				// To Set Port A as LCD'S Command Purpose
#define RS PA0					// To Set Port A Pin 0 as Register select pin
#define RW PA1					// To Set Port A Pin 1 as Read write pin
#define EN PA2					// To Set Port A Pin 2 as Enable pin

/* SUBROUTINE FUNCTIONS */

                                                // FUNCTION TO SEND LCD COMMAND  

void lcd_cmd(unsigned char cmd)
{
	LCD=cmd;
	CNT=(0<<RS);
	CNT=(0<<RW);
	CNT=(1<<EN);
	_delay_ms(1);
	CNT=(0<<RS);
	CNT=(0<<RW);
	CNT=(0<<EN);
	_delay_ms(50);
	return;
}

                                                // FUNCTION TO SEND LCD DATA 

void lcd_data(unsigned char data)
{
	LCD=data;
	CNT=(1<<RS);
	CNT=(0<<RW);
	CNT=(1<<EN);
	_delay_ms(1);
	CNT=(1<<RS);
	CNT=(0<<RW);
	CNT=(0<<EN);
	_delay_ms(50);
	return;
}

                                                // FUCTION TO PRINT STRING 
void lcd_string(unsigned char *str)
{
	int i;
	  while(str[i] != '\0')
		{
			lcd_data(str[i]);
			i++;
		}
}

/* MAIN FUNCTION */
void main()
{
	DDRD=0xff;				 // To Set Port A as Output
	DDRA=0x07;				 // To Set Port A as Output

			lcd_cmd(0x38);		 // For using 8-bit 2 row mode and 5x7 Dots of LCD
			_delay_ms(1);
		
			lcd_cmd(0x0e);		 // Turn display ON for cursor blinking
			_delay_ms(1);
		
			lcd_cmd(0x0c);		 // Display On cursor Off	
			_delay_ms(1);
		
			lcd_cmd(0x01);		 // Clear screen
			_delay_ms(1);
		
			_delay_ms(50);
			
			lcd_cmd(0x87);		 // Bring cursor to position 7 of ROW 1
			
			lcd_data('H');		 // Print Char
			
			lcd_data('I');		 // Print Char	
		
			lcd_data('!');		 // Print Char
		
			lcd_cmd(0xc4);		 // Bring cursor to position 4 of ROW 2
		
			lcd_string("**GUYS**");	 // Print String
			_delay_ms(1000);
			
			lcd_cmd(0x01);		 // Clear screen
			_delay_ms(1);
		
			lcd_cmd(0x83);		 // Bring cursor to position 3 of ROW 1
	
			lcd_string("WELCOME TO");// Print String
			_delay_ms(500);
			
			lcd_cmd(0xC4);		 // Bring cursor to position 4 of ROW 2
		
			lcd_string("GEMICATES"); // Print String
			_delay_ms(1000);
		while(1)
		{
			lcd_cmd(0x80);		 // Bring cursor to position 0 of ROW 1							
		
			lcd_string("PROGRESS THROUGH");
		
			lcd_cmd(0x1C);		 // Shift entire display left
		
			lcd_cmd(0xC3);		 // Bring cursor to position 3 of ROW 2							
		
			lcd_string("INNOVATION");
		
			lcd_cmd(0x18);		 // Shift entire display right
		}
}

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close